/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.session;

import frm.billingAndPaymentProcessing.entity.InvoiceEntity;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
@LocalBean
public class InvoiceSessionBean {

    @PersistenceContext
    private EntityManager em;

    public void createInvoice(InvoiceEntity invoice) {
        em.persist(invoice);
    }

    public InvoiceEntity getInvoiceById(Long invoiceId) {
        return em.find(InvoiceEntity.class, invoiceId);
    }

    public List<InvoiceEntity> getAllInvoice() {
        Query query = em.createQuery("SELECT u FROM InvoiceEntity u where u.abolished =0");
        return query.getResultList();
    }
    public List<InvoiceEntity>getAbolishedInvoice(){
        Query query = em.createQuery("SELECT u FROM InvoiceEntity u where u.abolished =1");
        return query.getResultList();
    }

    public void saveChanges(InvoiceEntity invoice) {
        em.merge(invoice);
    }
    public void removeInvoice(InvoiceEntity invoice){
        
        em.remove(invoice);
        
}
}  